package com.kfm.dao;

import com.kfm.model.Account;
import com.kfm.util.DBUtil;

import java.sql.SQLException;
import java.util.List;

public class AccountDao {

    private DBUtil<Account> dbUtil = new DBUtil<>();

    public Account selectByUsernameAndPass(String username, String pass){
        String sql = "select * from account where username = ? and pass = ?";
        try {
            return dbUtil.queryOne(sql, Account.class, username, pass);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    public List<Account> selectAll(){
        String sql = "select * from account";
        try {
            return dbUtil.queryList(sql, Account.class);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    public int deleteById(Integer id){
        String sql = "delete from account where id = ?";
        try {
            return dbUtil.update(sql, id);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return -1;
    }
}
